using System.Web.UI.WebControls;
using MVP.DTO;

namespace MVP.Web.Controls
{
    public class WebLookupList : ILookupList
    {
        private ListControl underlyingList;

        public WebLookupList(ListControl underlyingList)
        {
            this.underlyingList = underlyingList;
        }

        public void Add(ILookupDTO dto)
        {
            underlyingList.Items.Add(new ListItem(dto.Text, dto.Value));
        }

        public void Clear()
        {
            underlyingList.Items.Clear();
        }

        public ILookupDTO SelectedItem
        {
            get
            {
                ListItem item = underlyingList.SelectedItem;
                return new SimpleLookupDTO(item.Value, item.Text);
            }
        }
    }
}